package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.guild.gevent.GuildEvent;
import com.xcity.game.player.cache.PlayerCacheService;

import naga.x.App;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class GuildEventListResponse extends Response {

	public List<GEventInfo> list = null;
	public static class GEventInfo{
		public int type;
		public long src;
		public String sname;
		public long tgt;
		public String tname;
		public long time;
		public GEventInfo(GuildEvent event){
			this.type = event.getType();
			this.src = event.getSource();
			Player p = App.getApp().getServiceManager().get(PlayerCacheService.class).find(this.src);
			if(p != null){
				this.sname = p.getName();
			}
			this.tgt = event.getTarget();
			p = App.getApp().getServiceManager().get(PlayerCacheService.class).find(this.tgt);
			if(p != null){
				this.tname = p.getName();
			}
			time = event.getTime();
		}
	}
	
	
	public GuildEventListResponse(int serial, List<GuildEvent> events) {
		super(serial);
		list = new ArrayList<GEventInfo>();
		for(int i = 0; i < events.size(); i++){
			GEventInfo eventInfo = new GEventInfo(events.get(i));
			list.add(eventInfo);			
		}
	}
	public List<GEventInfo> getList() {
		return list;
	}
	public void setList(List<GEventInfo> list) {
		this.list = list;
	}
}
